<!DOCTYPE html>
<html>
<head>
	
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0" />
<title>蹭一族</title>
	<!-- Bootstrap 3.3.5 -->
  <link rel="stylesheet" href="/static/bootstrap/css/bootstrap.min.css"  />
  <!-- Font Awesome -->
  <link rel="stylesheet" href="/static/awesome/css/font-awesome.min.css" /> 
  <!-- Ionicons -->
  <link rel="stylesheet" href="/static/ionicon/css/ionicons.min.css" />
  <!-- DataTables -->
  <link rel="stylesheet" href="/static/plugins/datatables/dataTables.bootstrap.css">
   <!-- DataTables -->
  <link rel="stylesheet" href="https://cdn.datatables.net/1.10.11/css/jquery.dataTables.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="/static/dist/css/AdminLTE.min.css" />
  <!-- AdminLTE Skins. Choose a skin from the css/skins
       folder instead of downloading all of them to reduce the load. -->
  <link rel="stylesheet" href="/static/dist/css/skins/_all-skins.min.css" />
  
    <link rel="stylesheet" href="/static/js/img/img.css" type="text/css">
    
    
<link href="/static/bootstrapValidate/css/bootstrapValidator.min.css" rel="stylesheet" />
 <style>
 	tbody tr td{ text-align:center; }
 </style>

<!-- ./wrapper -->	

</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
	<#-- header -->
  <#include  "/admin/layouts/header.ftl" >
  
  <div class="content-wrapper">
  
  <section class="content-header">
      <h1>
        <span></span>
        <small>后台管理员</small>
      </h1>
      <ol class="breadcrumb">
        <li><a href="/manager/${sys}"><i class="fa fa-dashboard"></i>主页</a></li>
        <li class="active"   >后台管理员</li>
      </ol>
    </section>
 	 <#-- 左侧导航栏-->
  	<#if Session.session_admin_user['ROLE_CODE']=='ADMIN'>
 	 	<#include  "/admin/menu/sidebar_admin.ftl" />
	</#if>
	<#-- 左侧导航栏-->
  	<#if Session.session_admin_user['ROLE_CODE']=='ADMINISTRATOR'>
 	 	<#include  "/admin/menu/sidebar_administrator.ftl" />
	</#if>
    <#-- 内容 -->
    <section class="content"  >
       <table>
       		<tr>
       			<td>
       				<a class="btn btn-app" onclick="addFun()" >
	                	<i class="fa fa-plus"></i> 添加
	              	</a>
	              	<a class="btn btn-app" onclick="pwdFun()" >
	                	<i class="fa fa-expeditedssl"></i> 修改密码
	              	</a>
       			</td>
       		</tr>
       </table>
    
       <table id="datatable" class="table table-bordered table-striped">
                <thead>
	                <tr >
	                  <th>账号</th>
	                  <th>角色</th>
	                  <th>状态</th>
	                  <th>创建时间</th>
	                </tr>
                </thead>
        </table>
      
    </section>
  </div>
  
  
  <#-- /.content-wrapper -->
  <#include "/admin/layouts/footer.ftl" />

  <#-- Control Sidebar -->
  <#include  "/admin/layouts/controlSidebar.ftl" />
</div>

<!-- jQuery 2.1.4 -->
<script src="/static/plugins/jQuery/jQuery-2.1.4.min.js"></script>
<!-- jQuery UI 1.11.4 -->
<script src="/static/js/jqueryUi.min.1.11.4.js"></script>
<!-- Resolve conflict in jQuery UI tooltip with Bootstrap tooltip -->
<!-- Bootstrap 3.3.5 -->
<script src="/static/bootstrap/js/bootstrap.min.js"></script>
<!-- Morris.js charts 
<script src="/static/plugins/morris/morris.min.js"></script>
-->

<!-- DataTables -->
<script src="/static/plugins/datatables/jquery.dataTables.min.js"></script>
<script src="/static/plugins/datatables/dataTables.bootstrap.min.js"></script>
<!-- Slimscroll -->
<script src="/static/plugins/slimScroll/jquery.slimscroll.min.js"></script>
<!-- FastClick -->
<script src="/static/plugins/fastclick/fastclick.js"></script>
<!-- AdminLTE App -->
<script src="/static/dist/js/app.min.js"></script>

<#-- AdminLTE for demo purposes -->
<script src="/static/dist/js/demo.js"></script>
<!-- layer-->
<script src="/static/layer/layer.js"></script>

<!-- layer-->
<script src="/static/js/syUI.js"></script>


<script type="text/javascript" src="/static/js/uploadify/swfobject.js"></script>
<script type="text/javascript" src="/static/js/uploadify/jquery.uploadify.js"></script>
<!-- 引入ui扩展 -->
<script src="/static/js/core.ui.js" type="text/javascript" charset="utf-8"></script>
<!-- 引入图片裁剪-->
<link rel="stylesheet" href="/static/js/tapmodo-Jcrop-1902fbc/css/jquery.Jcrop.css" type="text/css">
<script type="text/javascript" src="/static/js/tapmodo-Jcrop-1902fbc/js/jquery.Jcrop.js"></script>
<script type="text/javascript" src="/static/js/tapmodo-Jcrop-1902fbc/js/jquery.Jcrop.min.js"></script>
<!-- 浏览大图 -->
<script type="text/javascript" src="/static/js/img/img.js"></script>

<script type="text/javascript" src="/static/js/ut.js" ></script>

<script src="/static/bootstrapValidate/js/bootstrapValidator.min.js"></script>

<script>
	var table ;
	var l = "";
	<#if location?? > 
		l = "${location}";
	</#if>
	$(function(){
		table = $("#datatable").dataTable({
	      "processing": true,
	      "serverSide": true,
	       ordering:false,
	       searching:false,
	      "ajax" : "/admin/list",
	       "oLanguage" : {
                "sLengthMenu": "每页显示 _MENU_ 条记录",
                "sZeroRecords": "抱歉， 没有找到",
                "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
                "sInfoEmpty": "没有数据",
                "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                "sZeroRecords": "没有检索到数据",
                "sSearch": "商家名称:",
                "oPaginate": {
                "sFirst": "首页",
                "sPrevious": "前一页",
                "sNext": "后一页",
                "sLast": "尾页"
                }
                     
            },
            "aoColumnDefs": [
			{
			 sDefaultContent: '',
			 aTargets: [ '_all' ]
			  }
			],
	      <!-- "fnServerData":retrieveData, //与后台交互获取数据的处理函数      -->
	      "columns": [
	       <!-- {"data": "id",sWidth:'3%'},, "bSortable": false -->
	        {
	        	"data": "username",sWidth:'10%'
	        },
	        {
	        	"data": "roleCode",sWidth:'10%'
	       	},
	        {
	        	"data": "state",sWidth:'10%',
	        	"render": function(value, type, row) {
	        		switch (value) {
						case 1:
							return UT.addSpanColor("当前在线","green")+"  &nbsp;&nbsp;&nbsp;<a href='javascript:void(0);' onclick='checkFun(\""+row.id+"\",0)' style='color:red' title='点击禁用'>禁用</a>";
						case 0:
							return UT.addSpanColor("当前禁用","gray")+"  &nbsp;&nbsp;&nbsp;<a href='javascript:void(0);' onclick='checkFun(\""+row.id+"\",1)' style='color:red' title='点击发送'>启用</a>";
					}
		         }
	        },
	        {"data": "createTime",sWidth:'10%'}
	      ]
	    });
	    
	    $("#datatable tbody").click(function (event) {
            $(table.fnSettings().aoData).each(function () {
                $(this.nTr).removeClass('selected');
            });
            $(event.target.parentNode).addClass('selected');
            
        });

        $('#datatable tbody tr').click(function (event) {
            var aData = table.fnGetData(this); // get datarow
            if (null != aData)  // null if we clicked on title row
            {
                var tt = aData[0];
                alert(tt);
               document.getElementById("Hidden1").value = tt;
            }
        });
	});
	
	var addFun = function(){
		var dialog = sy.modalDialog({
			title : '添加管理员',
			width : '600',
			height : '500',
			url : '/manager/${sys}/go/adminEdit',
			buttons : [ {
				text : '保存',
				handler : function() {
					dialog.find('iframe').get(0).contentWindow.submitForm(dialog, table, parent.$);
				}
			} ]
		});
	}
	
	var pwdFun = function(){
		var rows = sy.fnGetSelected(table);
		if (rows.length == 0) {
			parent.$.messager.w('请选择一个用户进行修改！');
			return;
		}
		parent.$.messager.prompt(false,'请输入新密码',function(r){
				if (r){
					if(r.length>20){
						parent.$.messager.e('请输入少于20位密码');
						return;
					}
					var data = {
							id : rows[0].id,
							password : r
					};
					SaveData(data);
				}
		});
		
	}
	
	var checkFun = function (id,type){
		var str = "您确定要启用该账号吗？";
		if(type==0) str="您确定要禁用该账号吗？";
		parent.$.messager.confirm("询问",str,function(r){
				if (r){
					 
					var data = {
							id : id,
							state : type
					};
					SaveData(data);
				}
		});
	}
	
	
	function SaveData(data) {
		$.post(sy.contextPath + '/admin/save', data, function() {
			table.fnDraw(false);
		}, 'json');
	}
</script>

</body>
</html>
